﻿@model IEnumerable<Citi.Scheduler.WebUi.Models.CategoryModel>
<script type="text/javascript">
    function expandColapse(id) {
        $("#imgExpand" + id).toggle();
        $("#imgColapse" + id).toggle();
        $("#divCategory" + id).toggle();
    }
</script>
@section Menu
{
    @Html.Partial("~/Views/Menu/Entries.cshtml", new ViewDataDictionary())
}
@{
    //var categories = Model.Select(x => x.ParentId).Distinct().Count() > 1 ? Model.Where(x => x.ParentId == null) : Model;
    var parentId = Model.Any() && Model.First().ParentId != null ? Model.First().ParentId.Value.ToString() : string.Empty;   
    
    <div class="listTab" id="@string.Concat("divCategory", parentId)" style="@(!string.IsNullOrEmpty(parentId) ? "display:none;" : "") ">
        @foreach (var item in Model)
        {
            //var parentId = item.ParentId;
            //var children = Model.Where(x => x.ParentId == item.Id);

            <div class="floatLeft" style="width: 15px;">
                @if (item.Children.Any())
                {
                    <img src="@Url.Content("~/Content/Images/Expand.gif")" alt="Expand" id="@string.Concat("imgExpand", item.Id)" onclick="expandColapse('@item.Id')"/>
                    <img src="@Url.Content("~/Content/Images/Colapse.gif")" alt="Colapse" id="@string.Concat("imgColapse", item.Id)" onclick="expandColapse('@item.Id')" style="display: none;"/>
                }
            </div>
              
            <div class="floatLeft" onmouseover="$('#@string.Concat("categoryActions", item.Id)').css('display', 'inline');" onmouseout="$('#@string.Concat("categoryActions", item.Id)').hide();">
                @Html.DisplayFor(modelItem => item.Name)
                <div id="@string.Concat("categoryActions", item.Id)" style="margin-left: 15px; display:none;">
                    @Ajax.ActionLink("Edit", "ActionForm", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "divUpdateCategory", OnBegin = "openUpdateCategoryDialog" }, new { @class = "icon-pencil" })
                    |
                    @Ajax.ActionLink("Delete", "Delete", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "divIndexCategory", Confirm = "Are you sure?" }, new { @class = "icon-remove" })
                </div>
            </div>
            
            <br/>
                if (item.Children.Any())
                {
            
            @Html.Partial("Index", item.Children)
                }


        }
    </div>
}
